package blazingbubble.gui.elements;

import java.awt.Component;
import java.awt.Font;
import java.awt.FontFormatException;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

import javax.swing.JTable;
import javax.swing.table.TableCellRenderer;
import javax.swing.table.TableModel;

import blazingbubble.gui.Resources;

public class MenuTable extends JTable{
	private static final long serialVersionUID = -3816276655634768937L;
	
	private Font font = null;
	public MenuTable(TableModel tableModel, int fontStyle, float fontSize){
		super(tableModel);
		
		FileInputStream inputStream = null;
		try {
			inputStream = new FileInputStream(new File((Resources.CRAYON_FONT_PATH)));
			font = (Font.createFont(Font.TRUETYPE_FONT, inputStream).deriveFont(fontStyle, fontSize));
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (FontFormatException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		finally {
			if (inputStream != null){
				try {
					inputStream.close();
				}
				catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
		this.setFont(font);
		this.getTableHeader().setFont(font);
	}
	
	@Override
	public Component prepareRenderer(TableCellRenderer renderer, int row, int column) {
		Component c = super.prepareRenderer(renderer, row, column);
		if (font != null) {
			c.setFont(font);
		}
		return c;
	}
}
